package graph.element.shape;

import graph.GraphPanel;
import graph.color.Color;
import graph.element.element;

import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;


public abstract class Shape extends element {
	protected boolean value;
	protected int val;
	protected double x;
	protected double y;
	protected java.awt.Color color;
	public Shape(GraphPanel graphingData, double x, double y, boolean value, Color color, int val, int max) {
		super(graphingData);
		this.val = val;
		this.value = value;
		this.x = x;
		this.y = y;
		this.color = color.get((float)(Math.log(val)/Math.log(max)));
	}
	public void drawValue() {
		if (value) {
			Graphics g = getG();
			Graphics2D g2 = (Graphics2D)g;
			java.awt.Color restore = g2.getColor();
	    	g2.setColor(java.awt.Color.WHITE);
	    	FontMetrics fm = g.getFontMetrics();
	    	int width = fm.stringWidth("" + val);
	    	int height = fm.getHeight();
	    	g2.drawString("" + val, (int) (x - width/2), (int) (y + height/3));
	    	g2.setColor(restore);
		}
	}
}
